<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>小硕工具箱</title>
    <style>
        body {
            margin: 0;
            padding: 0;
            font-family: Arial, sans-serif;
        }
        .container {
            width: 100%;
            height: 100vh;
            display: flex;
            flex-direction: column;
            align-items: center;
        }
        #targetFrame {
            width: 100%;
            height: 100%;
            border: none;
        }
        .loading {
            position: fixed;
            top: 50%;
            left: 50%;
            transform: translate(-50%, -50%);
            background: rgba(255, 255, 255, 0.9);
            padding: 20px;
            border-radius: 8px;
            box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
            display: none;
        }
    </style>
</head>
<body>
    <div class="container">
        <iframe id="targetFrame" title="动态加载内容"></iframe>
        <div id="loading" class="loading">加载中...</div>
    </div>

    <script>
        document.addEventListener('DOMContentLoaded', async () => {
            const iframe = document.getElementById('targetFrame');
            const loading = document.getElementById('loading');

            try {
                loading.style.display = 'block';
                const response = await fetch('http://115.190.90.79:58001/api/get');
                console.log(response)
                if (!response.ok) {
                    throw new Error(`HTTP error! status: ${response.status}`);
                }
                const { url, logo, title } = await response.json();
                if (url) {
                    iframe.src = url;
                }
                // 更新页面标题
                if (title) {
                    document.title = title;
                }
                // 更新网站图标
                if (logo) {
                    // 移除现有的favicon
                    const existingFavicon = document.querySelector("link[rel='icon']");
                    if (existingFavicon) {
                        existingFavicon.remove();
                    }
                    // 创建新的favicon
                    const favicon = document.createElement('link');
                    favicon.rel = 'icon';
                    favicon.href = logo;
                    document.head.appendChild(favicon);
                }
            } catch (error) {
                console.error('获取URL失败:', error);
                alert('加载内容失败，请稍后重试');
            } finally {
                loading.style.display = 'none';
            }
        });
    </script>
</body>
</html>
